/**
 * 
 */
package br.com.binding.rebind;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JField;


/**
 * @author USER
 *
 */
public class BoundModelClass {
    
    private JClassType type;
    private JClassType modelType;
    private Map<JField, List<ListenerTemplate>> listenersMap;
    
    public BoundModelClass(JClassType type){
        this.listenersMap = new HashMap<JField, List<ListenerTemplate>>();
        this.type = type;
    }

    public JField[] getFields() {
        return type.getFields();
    }

    public String getPackageName() {
        return type.getPackage().getName();
    }

    public String getClassName() {
        return type.getSimpleSourceName();
    }
    
    public void associateFieldListener(JField field, ListenerTemplate listener){
        if(listenersMap.containsKey(field)){
            List<ListenerTemplate> currentListeners = listenersMap.get(field);
            currentListeners.add(listener);
        }
        else{
            List<ListenerTemplate> templates = new ArrayList<ListenerTemplate>();
            templates.add(listener);
            listenersMap.put(field, templates);
        }
    }
    
    public void removeFieldListener(JField field, ListenerTemplate listener){
        if(listenersMap.containsKey(field)){
            List<ListenerTemplate> currentListeners = listenersMap.get(field);
            currentListeners.remove(listener);
        }
    }
    
    /**
     * @return the listenerMap
     */
    public Map<JField, List<ListenerTemplate>> getListenersMap() {
        return listenersMap;
    }

	public String getSuperClassName() {
		return type.getSuperclass().getName();
	}

	/**
	 * @return the modelType
	 */
	public JClassType getModelType() {
		return modelType;
	}

	/**
	 * @param modelType the modelType to set
	 */
	public void setModelType(JClassType modelType) {
		this.modelType = modelType;
	}
    
    
}
